package com.hoaresky.redisdemo.controller;

import com.hoaresky.redisdemo.entity.User;
import com.hoaresky.redisdemo.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Hoaresky.
 * 2018-03-09 23:44
 */
@RestController
@RequestMapping("/api")
public class RedisController {
    @Autowired
    private RedisService redisService;

    private final String USER_KEY="hongxuelin";

    /**
     * redis 的 set 测试
     * @return
     */
    @RequestMapping("/set")
    public String set(){
        User user = new User();
        user.setId(1);
        user.setPassword("hongxuelin");
        user.setUsername("admin");
        redisService.set(USER_KEY,user);
        return user.toString();
    }

    /**
     * redis 的 get 测试
     * @return
     */
    @RequestMapping("/get")
    public String get(){
        User u = (User)redisService.get(USER_KEY);
        return u.toString();
    }

}
